#ifndef __RISCV32_REG_H__
#define __RISCV32_REG_H__

#include "common.h"

#define PC_START (0x80000000u + IMAGE_START)

#define CSR_SSTATUS   0x100
#define CSR_STVEC     0x105
#define CSR_SEPC      0x141
#define CSR_SCAUSE    0x142
#define CSR_SATP      0x180


typedef struct {
  struct {
    rtlreg_t _32;
  } gpr[32];

  vaddr_t pc;

  rtlreg_t stvec;
  rtlreg_t sepc;
  rtlreg_t scause;
  rtlreg_t sstatus;
  rtlreg_t satp;

} CPU_state;

static inline int check_reg_index(int index) {
  assert(index >= 0 && index < 32);
  return index;
}

#define reg_l(index) (cpu.gpr[check_reg_index(index)]._32)

#define reg_stvec   (cpu.stvec  )
#define reg_sepc    (cpu.sepc   )
#define reg_scause  (cpu.scause )
#define reg_sstatus (cpu.sstatus)
#define reg_satp    (cpu.satp)


static inline const char* reg_name(int index, int width) {
  extern const char* regsl[];
  assert(index >= 0 && index < 32);
  return regsl[index];
}

#endif
